import React, {useRef} from 'react'
import { PageHeaderWrapper } from '@ant-design/pro-layout'
import ProTable from '@ant-design/pro-table'
import { connect } from 'umi'
import { getLeaveList} from '../service'
import { BPMStatusEnum, vacationType } from '@/utils/constant'
import moment from 'moment'

const TableList = () => {
  const actionRef = useRef();

  const columns = [
    {
      title: '工号',
      hideInSearch: true,
      dataIndex: 'code',
      key:'code',
    },
    {
      title: '姓名',
      dataIndex: 'name',
      key:'name'
    },
    {
      title: '公司',
      dataIndex: 'orgname',
      key:'orgname'
    },
    {
      title: '部门',
      dataIndex: 'unitname',
      key:'unitname'
    },
    {
      title: '岗位',
      dataIndex: 'jobname',
      key:'jobname'
    },
    {
      title: '请假/调休天数',
      dataIndex: 'leaveDay',
      hideInSearch: true,
      key:'leaveDay',
      render:(text) => {
        return text + "天";
      }
    },
    {
      title: '请假类型',
      dataIndex: 'type',
      key:'type',
      hideInSearch: true,
      render: (text) => {
        const res = vacationType.find((item) => item.value === parseInt(text))
        return res ? res.label : text
      },
    },
    {
      title: '假期开始日期',
      dataIndex: 'leaveBeginTime',
      hideInSearch: true,
      render: (text) => {
        return moment(text).format('YYYY-MM-DD');
      },
    },
    {
      title: '审批状态',
      dataIndex: 'dealStatus',
      key:'dealStatus',
      hideInSearch: true,
      valueEnum: BPMStatusEnum
    }
  ];

  return (
    <PageHeaderWrapper>
      <ProTable
        actionRef={actionRef}
        rowKey="id"
        request={(params) => getLeaveList(params)}
        columns={columns}
      />
    </PageHeaderWrapper>
  )
};

export default connect(({}) => ({
}))(TableList)
